package com.ruoyi.cms.navType.service.Impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cms.navType.mapper.CmsNavTypeMapper;
import com.ruoyi.cms.navType.domain.CmsNavType;
import com.ruoyi.cms.navType.service.ICmsNavTypeService;

import javax.annotation.Resource;

/**
 * 菜单类别Service业务层处理
 *
 * @author linyang
 * @date 2025-07-28
 */
@Service
public class CmsNavTypeServiceImpl implements ICmsNavTypeService {
    @Resource
    private CmsNavTypeMapper cmsNavTypeMapper;

    /**
     * 查询菜单类别
     *
     * @param id 菜单类别主键
     * @return 菜单类别
     */
    @Override
    public CmsNavType selectCmsNavTypeById(Long id) {
        return cmsNavTypeMapper.selectCmsNavTypeById(id);
    }

    /**
     * 查询菜单类别列表
     *
     * @param cmsNavType 菜单类别
     * @return 菜单类别
     */
    @Override
    public List<CmsNavType> selectCmsNavTypeList(CmsNavType cmsNavType) {
        return cmsNavTypeMapper.selectCmsNavTypeList(cmsNavType);
    }

    /**
     * 新增菜单类别
     *
     * @param cmsNavType 菜单类别
     * @return 结果
     */
    @Override
    public int insertCmsNavType(CmsNavType cmsNavType) {
        cmsNavType.setCreateTime(DateUtils.getNowDate());
        return cmsNavTypeMapper.insertCmsNavType(cmsNavType);
    }

    /**
     * 修改菜单类别
     *
     * @param cmsNavType 菜单类别
     * @return 结果
     */
    @Override
    public int updateCmsNavType(CmsNavType cmsNavType) {
        cmsNavType.setUpdateTime(DateUtils.getNowDate());
        return cmsNavTypeMapper.updateCmsNavType(cmsNavType);
    }

    /**
     * 批量删除菜单类别
     *
     * @param ids 需要删除的菜单类别主键
     * @return 结果
     */
    @Override
    public int deleteCmsNavTypeByIds(Long[] ids) {
        return cmsNavTypeMapper.deleteCmsNavTypeByIds(ids);
    }

    /**
     * 删除菜单类别信息
     *
     * @param id 菜单类别主键
     * @return 结果
     */
    @Override
    public int deleteCmsNavTypeById(Long id) {
        return cmsNavTypeMapper.deleteCmsNavTypeById(id);
    }


    /**
     * 修改类别状态
     *
     * @param cmsNavType
     * @return
     */
    public int updateCmsNavTypeStatus(CmsNavType cmsNavType) {
        LambdaUpdateWrapper<CmsNavType> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.set(CmsNavType::getStatus, cmsNavType.getStatus());
        lambdaUpdateWrapper.set(CmsNavType::getUpdateBy, cmsNavType.getUpdateBy());
        lambdaUpdateWrapper.set(CmsNavType::getUpdateTime, DateUtils.getNowDate());
        lambdaUpdateWrapper.eq(CmsNavType::getId, cmsNavType.getId());
        return cmsNavTypeMapper.update(null, lambdaUpdateWrapper);
    }
}